var _n53;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var $1$Loader = require("Loader");
var c = cc__importDefault($1$Loader);
var $1$yyComponent = require("yyComponent");
var l = cc__importDefault($1$yyComponent);
var $GameEventType = require("GameEventType");
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $1$userService = require("userService");
var d = cc__importDefault($1$userService);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_gameListItemNew = function (t) {
  function _ctor() {
    // 调用t函数并获取上下文，若返回为null，则使用当前对象
    var context = null !== t && t.apply(this, arguments) || this;

    // 初始化属性为null
    context.icon = null;
    context.vicon = null;
    context.gameName = null; // 修正变量名拼写错误
    context.tips = null;
    context.lockNode = null;
    context.huise = null;
    context.zhengchang = null;

    // 定义玩家等级名称
    context.playGradeName = [
      "乞丐", "书童", "书生", "秀才", "举人", "进士",
      "探花", "榜眼", "状元", "知县", "博士", "知州",
      "知府", "中书令", "巡抚", "丞相", "驸马", "皇帝",
      "增福神", "财神", "天将", "东帝", "天王", "神君",
      "星君", "天尊", "东王公", "玉帝"
    ];

    // 初始化data属性为null
    context.data = null;

    // 返回上下文对象
    return context;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () {
    this.on($GameEventType.EventType.UIEvent.updataGamelist, this.updataView, this);
  };
  _ctor.prototype.setData = function (t) {
    cc.log(t);
    this.data = t;
    this.updataView();
  };
  _ctor.prototype.updataView = function () {
    var context = this; // 缓存当前上下文

    // 检查是否存在数据
    if (this.data) {
      var data = this.data; // 缓存数据以便使用
      this.gameName.string = data.name; // 更新游戏名称

      // 根据解锁等级设置图标和提示
      if (+data.lockLevel < 1) {
        this.vicon.children[0].active = true; // 显示已解锁图标
        this.vicon.children[1].active = false;
        this.tips.string = ""; // 清空提示
        this.tips.node.active = false; // 隐藏提示
        this.lockNode.active = true; // 显示锁定状态
      } else {
        this.vicon.children[0].active = false; // 隐藏已解锁图标
        this.vicon.children[1].active = true; // 显示未解锁图标
        this.tips.string = "需达到" + this.playGradeName[data.lockLevel] + "解锁"; // 设置提示信息
        this.lockNode.active = false; // 隐藏锁定状态
      }

      // 检查是否具有体验权限
      if ($zqcc_OverallSystem.sers().userSrv.getTiyanGame().indexOf(data.lockName) >= 0 ||
        Number($zqcc_OverallSystem.sers().localStorageSrv.get(d.default.changwanModel)) === 1) {
        this.vicon.children[0].active = true; // 显示已解锁图标
        this.vicon.children[1].active = false;
        this.tips.node.active = false; // 隐藏提示
        this.lockNode.active = true; // 显示锁定状态
      }

      // 设置图标材质
      var material = this.lockNode.active ? this.zhengchang : this.huise; // 判断使用的材质
      this.icon.setMaterial(0, material);
      this.icon.node.children[0].getComponent(cc.Sprite).setMaterial(0, material);

      // 加载图标资源
      c.default.loadBundleRes("mainScene", "icon/" + this.data.icon, function (resource) {
        if (context && context.node) {
          context.icon.spriteFrame = new cc.SpriteFrame(resource); // 设置图标精灵帧
        }
      });
    }
  };
  _ctor.prototype.onTouchStart = function () {
    // 优化后的代码
    const currentContext = this; // 使用const替代var，并且修改变量名为具意义的名称
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();

    if (this.vicon.children[1].active) {
      // 加载并显示视频广告
      $zqcc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(
        async () => {
          const temporaryArray = $zqcc_OverallSystem.sers().userSrv.getTiyanGame();
          temporaryArray.push(currentContext.data.lockName);
          $zqcc_OverallSystem.sers().userSrv.setTiyanGame(temporaryArray);
          s.default.emit($GameEventType.EventType.UIEvent.updataGamelist);
        },
        () => { },
        null,
        {
          game_name: "主场景更多游戏",
          prop_name: "解锁",
          level: this.data.gameType,
          slevel: this.data.name
        },
        "common_video"
      );
    } else if (this.data.gameType !== 10) { // 改为使用严格不等于
      if ($zqcc_OverallSystem.sers().userSrv.power <= 0) {
        return void $zqcc_OverallSystem.sers().uiSrv.showUserGetPowerPage(); // 欢迎页面展示
      }
      $zqcc_OverallSystem.sers().userSrv.addPower(-1); // 减去力量值
      $zqcc_OverallSystem.sers().userSrv.setGameList(this.data.gameType);
      $zqcc_OverallSystem.mgrs().gameMgr.enterMode(this.data.gameType); // 进入指定模式
    } else {
      $zqcc_OverallSystem.sers().uiSrv.showModeSelectPage(); // 显示模式选择页面
    }
  };
  cc__decorate([ccp_property(cc.Sprite)], _ctor.prototype, "icon", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "vicon", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "gameNmae", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "tips", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lockNode", undefined);
  cc__decorate([ccp_property(cc.Material)], _ctor.prototype, "huise", undefined);
  cc__decorate([ccp_property(cc.Material)], _ctor.prototype, "zhengchang", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(l.default);
exports.default = def_gameListItemNew;